package mylistdemo001;

import java.util.ArrayList;
import java.util.StringJoiner;

/**
 *要求：定义一个集合，添加字符串，并进行遍历
 * 遍历格式参照：[元素1，元素2，元素3]
 */
public class ArrayListPractice01 {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("元素1");
        list.add("元素2");
        list.add("元素3");
        System.out.print("[");
        for (int i = 0; i < list.size(); i++) {
          if (i== list.size()-1){
              System.out.print(list.get(i));
          }else {
              System.out.print(list.get(i)+",");
          }
        }
        System.out.print("]");
    }
}
